<?php

namespace App\Http\Requests\Admin\Panx\Product;

use App\Http\Requests\ApiRequest;
use App\Models\Panx\Brand;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property string url
 * @property string logo
 */

class ProductBrandStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique('brands', 'name')->where(function($query) {
                return $query->where('customer_id', Brand::CUSTOMER_ID_PANX);
            })],
            'url'  => 'nullable|url|max:'.self::MAX_STRING,
            'logo' => 'required|string',
        ];
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.unique' => '品牌名称必须唯一，数据库中已有同名品牌',
//            'name.*'      => '品牌名称必须是字符串',
//            'url.*'       => '品牌url必须是合法网址',
//            'logo.*'      => '品牌logo必须是小于2M的图片',
//        ];
//    }
}
